﻿using System;
using System.Windows.Forms;

namespace ALDIOrganizer
{
    public partial class TemplateModificationReaction : Form
    {
        public TemplateDecision Result;

        public string DecidedAlternativeName
        {
            get
            {
                return _decidedAlternative ?? String.Empty;
            }
        }

        readonly string _template;
        readonly string _rota;
        string _decidedAlternative;

        public TemplateModificationReaction()
        {
            InitializeComponent();
        }
        
        string ReplaceWildcards(string pInput)
        {
            var result = pInput.Replace(
                "#",
                _template);
            result = result.Replace(
                "$",
                _rota);
            return result;                
        }

        public TemplateModificationReaction(Rota pRota, Template pTemplate)
            : this()
        {
            _template = pTemplate.Name;
            _rota = pRota.bndDays;

            Text = ReplaceWildcards(Text);
            lbMessage.Text = ReplaceWildcards(lbMessage.Text);
            btnModifyAnyway.Text = ReplaceWildcards(btnModifyAnyway.Text);
            btnModifyJustForThisRota.Text = ReplaceWildcards(btnModifyJustForThisRota.Text);
        }

        public override sealed string Text
        {
            get { return base.Text; }
            set { base.Text = value; }
        }
        
        private void btnModifyAnyway_Click(object sender, EventArgs e)
        {
            Result = TemplateDecision.ModifyExisting;
            Close();
        }

        private void btnModifyJustForThisRota_Click(object sender, EventArgs e)
        {
            Result = TemplateDecision.Rename;
            Program.inputTemplateNameForm = new formInputTemplateName(_template);
            if (Program.inputTemplateNameForm.ShowDialog() == DialogResult.OK)
            {
                _decidedAlternative = Program.inputTemplateNameForm.Result;
                Close();
            }
            Program.inputTemplateNameForm.Dispose();
        }
        
    }
}
